<html xmlns:th="http://www.thymeleaf.org">

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="vlogCensorDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="vlogCensorToolbar" style="display: none;">
    <div th:if="${@sec.hasPermission('vlogCensor:add')}">
        <a onclick="vlogCensorAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'glyphicon-plus icon-green'">添加</a>
    </div>
</div>

<script type="text/javascript" th:inline="javascript">
    var vlogCensorDataGrid;
    $(function() {
        vlogCensorDataGrid = $('#vlogCensorDataGrid').datagrid({
            url : basePath + '/vlogCensor/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 2,
            pageList : [ 2,10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            frozenColumns : [ [ {
                width : '50',
                title : '编号',
                field : 'id',
                sortable : true
            } ] ],
            columns : [ [ {
                width : '80',
                title : '博客id',
                field : 'vlogId'
            } , {
                width : '80',
                title : '手表账号id',
                field : 'watchId'
            },  {
                width : '80',
                title : '文字内容',
                field : 'text'
            },  {
                width : '80',
                title : '文字审核结果',
                field : 'textStatus',
                formatter:function (value,row,index) {
                    if(value == 0){
                        return "正常";
                    }
                    if(value == 2){
                        return "违规";
                    }
                }
            },  {
                width : '80',
                title : '视频内容',
                field : 'video'
            },  {
                width : '80',
                title : '视频审核结果',
                field : 'videoStatus',
                formatter:function (value,row,index) {
                    if(value == 0){
                        return "正常";
                    }
                    if(value == 1){
                        return "存疑";
                    }
                    if(value == 2){
                        return "违规";
                    }
                }
            }, {
                width : '80',
                title : '视频违规类型',
                field : 'invalidType'

            },  {
                width : '80',
                title : '审核人',
                field : 'auditor'
            },  {
                width : '80',
                title : '审核状态',
                field : 'status',
                formatter:function (value,row,index) {
                    if(value == 0){
                        return "待审核";
                    }
                    if(value == 1){
                        return "审核通过";
                    }
                    if(value == 2){
                        return "审核不通过";
                    }
                }
            },  {
                width : '130',
                title : '创建时间',
                field : 'createTime'

            },  {
                width : '130',
                title : '更新时间',
                field : 'updateTime'
            }, {
                field : 'auditTime',
                title : '审核时间',
                width : '130'
            }, {
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    //row 当前行对象
                    var str = '';

                    str += $.formatString('<a href="javascript:void(0)" class="vlogCensor-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'glyphicon-pencil icon-blue\'" onclick="vlogCensorEditFun(\'{0}\');" >编辑</a>', row.id);

                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="vlogCensor-easyui-linkbutton-del" data-options="plain:true,iconCls:\'glyphicon-trash icon-red\'" onclick="vlogCensorDeleteFun(\'{0}\');" >删除</a>', row.id);

                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.vlogCensor-easyui-linkbutton-ok').linkbutton({text:'授权'});
                $('.vlogCensor-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.vlogCensor-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#vlogCensorToolbar'
        });
    });

    /**
     * 添加框
     * @param url
     */
    function vlogCensorAddFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 650,
            height : 500,
            href : basePath + '/vlogCensor/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = vlogCensorDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#vlogCensorAddForm');
                    f.submit();
                }
            } ]
        });
    }

    /**
     * 编辑
     */
    function vlogCensorEditFun(id) {

        parent.$.modalDialog({
            title : '编辑',
            width : 650,
            height : 500,
            //一个url代表后台的一个方法
            href : basePath + '/vlogCensor/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = vlogCensorDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#vlogCensorEditForm');
                    f.submit();
                }
            } ]
        });
    }

    /**
     * 删除
     */
    function vlogCensorDeleteFun(id) {

        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post(basePath + '/vlogCensor/delete', {
                    id : id
                }, function(result) {
                    if (result.code === 1) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        vlogCensorDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }

    /**
     * 授权
     */
    function grantRoleFun(id) {
        if (id === undefined) {
            var rows = vlogCensorDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            vlogCensorDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '授权',
            width : 500,
            height : 500,
            href : basePath + '/vlogCensor/grantPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = vlogCensorDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#vlogCensorGrantForm');
                    f.submit();
                }
            } ]
        });
    }
</script>
